package io.renren.modules.generator.controller;

import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.modules.generator.entity.StationEntity;
import io.renren.modules.generator.service.StationService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import io.renren.common.utils.R;




/**
 * 气象数据管理
 * 
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2018-04-18 17:30:13
 */
@RestController
@RequestMapping("station")
public class StationController {
	@Autowired
	private StationService stationService;

	/**
	 * 列表
	 */
	@RequestMapping("/list")
	@RequiresPermissions("station:list")
	public R list(@RequestParam Map<String, Object> params) {
		//查询列表数据
		Query query = new Query(params);

		List<StationEntity> stationList = stationService.queryList(query);
		int total = stationService.queryTotal(query);

		PageUtils pageUtil = new PageUtils(stationList, total, query.getLimit(), query.getPage());

		return R.ok().put("page", pageUtil);
	}


	/**
	 * 信息
	 */
	@RequestMapping("/info/{flowId}")
	@RequiresPermissions("station:info")
	public R info(@PathVariable("flowId") Integer flowId) {
		StationEntity station = stationService.queryObject(flowId);

		return R.ok().put("station", station);
	}

	/**
	 * 保存
	 */
	@RequestMapping("/save")
	@RequiresPermissions("station:save")
	public R save(@RequestBody StationEntity station) {
		stationService.save(station);

		return R.ok();
	}

	/**
	 * 修改
	 */
	@RequestMapping("/update")
	@RequiresPermissions("station:update")
	public R update(@RequestBody StationEntity station) {
		stationService.update(station);

		return R.ok();
	}

	/**
	 * 删除
	 */
	@RequestMapping("/delete")
	@RequiresPermissions("station:delete")
	public R delete(@RequestBody Integer[] flowIds) {
		stationService.deleteBatch(flowIds);

		return R.ok();
	}

	@RequestMapping("/timelist")
	@RequiresPermissions("station:list")
	public R timelist(@RequestParam Map<String, Object> params) {
		//查询列表数据
		Query query = new Query(params);

		List<StationEntity> nppList = stationService.timeList(query);
		int total = stationService.timeTotal(query);

		PageUtils pageUtil = new PageUtils(nppList, total, query.getLimit(), query.getPage());

		return R.ok().put("page", pageUtil);
		//return R.ok(starttime);

	}
}
